package com.sixteen.theGreat.workbench.web.controller;

import com.sixteen.theGreat.commons.constants.Constants;
import com.sixteen.theGreat.commons.utils.UUIDUtil;
import com.sixteen.theGreat.settings.entity.User;
import com.sixteen.theGreat.workbench.entity.FriendList;
import com.sixteen.theGreat.workbench.service.FriendListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class FriendListController {
    @Autowired
    private FriendListService friendListService;

    /**
     * 通过输入好友代码 添加好友
     * @param friendId
     * @param request
     * @return
     */
    @PostMapping("/workbench/main/addFriendList.do")
    @ResponseBody
    public Object addFriendList(String friendId, HttpServletRequest request){
        User sessionUser = (User) request.getSession().getAttribute(Constants.SESSION_USER);
        FriendList friendList = FriendList.builder().friendListId(UUIDUtil.getUUID())
                .hostId(sessionUser.getUserId())
                .friendId(friendId).build();
        return friendListService.addFriendList(friendList);
    }

    /**
     * 查询我的所有好友
     * @param request
     * @return
     */
    @GetMapping("/workbench/main/queryFriendListByUserId.do")
    @ResponseBody
    public List<FriendList> queryFriendListByUserId(HttpServletRequest request){
        User sessionUser= (User) request.getSession().getAttribute(Constants.SESSION_USER);
        return friendListService.queryFriendListByUserId(sessionUser.getUserId());
    }
}
